namespace TFSChangeLog.ViewModel
{
    using System.Threading;
    using System.Windows.Input;
    using TFSChangeLog.Operations.Command;

    /// <summary>Summary description for <see cref="ProgressDialogViewModel"/> class.</summary>
    public class ProgressDialogViewModel : ViewModelBase
    {
        #region Fields

        /// <summary>Summary description for class level field of type <c>string</c>.</summary>
        private string p_ProgressMessage;

        /// <summary>Summary description for class level field of type <c>TFSChangeLog.ViewModel.MainWindowViewModel</c>.</summary>
        private MainWindowViewModel m_Parent;

        /// <summary>Summary description for class level field of type <c>string</c>.</summary>
        private string m_CancellationMessage;

        #endregion

        #region Constructor

        /// <summary>Initializes a new instance of the <see cref="ProgressDialogViewModel"/> class.</summary>
        /// <param name="mainWindowViewModel">TODO: Summary description for <c>mainWindowViewModel</c> parameter of type <c>TFSChangeLog.ViewModel.MainWindowViewModel</c>.</param>
        public ProgressDialogViewModel(MainWindowViewModel mainWindowViewModel)
        {
            this.Initialize(mainWindowViewModel);
        }

        #endregion

        #region Properties

        /// <summary>Gets or sets the value for TokenSource.</summary>
        public CancellationTokenSource TokenSource { get; set; }

        /// <summary>Gets or sets a value indicating whether IsCancelled is true or false.</summary>
        public bool IsCancelled { get; set; }

        /// <summary>Gets or sets the value for Cancel.</summary>
        public ICommand Cancel { get; set; }

        /// <summary>Gets or sets the value for ProgressMessage.</summary>
        public string ProgressMessage
        {
            get
            {
                return this.p_ProgressMessage;
            }

            set
            {
                this.p_ProgressMessage = value;
                this.OnPropertyChanged("ProgressMessage");
            }
        }

        #endregion

        #region Methods

        /// <summary>Summary description for <c>ProgressDialogViewModel</c> method.</summary>
        internal void ResetViewModel()
        {
            this.p_ProgressMessage = "Preparing while connecting to TFS Server.";
            this.IsCancelled = false;
        }

        /// <summary>Summary description for <c>ProgressDialogViewModel</c> method.</summary>
        /// <param name="m_message">TODO: Summary description for <c>m_message</c> parameter of type <c>string</c>.</param>
        internal void SetProgressMessage(string m_message)
        {
            this.ProgressMessage = m_message;
        }

        /// <summary>Summary description for <c>ProgressDialogViewModel</c> method.</summary>
        internal void ShowCancellationMessage()
        {
            this.ProgressMessage = this.m_CancellationMessage;
        }

        /// <summary>Summary description for <c>ProgressDialogViewModel</c> method.</summary>
        /// <param name="mainWindowViewModel">TODO: Summary description for <c>mainWindowViewModel</c> parameter of type <c>TFSChangeLog.ViewModel.MainWindowViewModel</c>.</param>
        private void Initialize(MainWindowViewModel mainWindowViewModel)
        {
            this.m_Parent = mainWindowViewModel;
            this.m_CancellationMessage = "Work Cancelled.";
            this.Cancel = new CancelCommand(this);
            this.ResetViewModel();
        }

        /// <summary>Summary description for <c>ProgressDialogViewModel</c> method.</summary>
        /// <returns>TODO: returns an object of type <c>TFSChangeLog.ViewModel.MainWindowViewModel</c>.</returns>
        public MainWindowViewModel GetMainWindowViewModel()
        {
            return this.m_Parent;
        }
        #endregion
    }
}